<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="YXBJ Windows/601568 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="576"/>
<h1>02-分支结构</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>创建时间：</b></td><td><i>2018/4/2 19:28</i></td></tr>
<tr><td><b>更新时间：</b></td><td><i>2020/3/29 12:28</i></td></tr>
<tr><td><b>作者：</b></td><td><i>18081003141@163.com</i></td></tr>
</table>
</div>
<br/>

<div>
<span><div><div><span style="font-size: 18pt;">程序执行结构</span></div><div><br clear="none"/></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-variant-caps: normal; font-variant-ligatures: normal; line-height: 16.2pt;">顺序结构：按照由上到下的顺序一行一行地执行的程序结构</span></span></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><div><br clear="none"/></div></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><div><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-variant-caps: normal; font-variant-ligatures: normal; line-height: 16.2pt;"><img src="00-笔记_files/做学霸.JPEG" type="image/jpeg" data-filename="做学霸.JPEG" style="font-size: 14pt;"/></span></span></div></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><div><br clear="none"/></div></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><div><br clear="none"/></div></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-variant-caps: normal; font-variant-ligatures: normal; line-height: 16.2pt;">分支结构：根据不同的条件判断来决定程序执行走向的结构（也叫选择结构）</span></span></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><div><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-variant-caps: normal; font-variant-ligatures: normal; line-height: 16.2pt;"><img src="00-笔记_files/做不做学霸.jpg" type="image/jpeg" data-filename="做不做学霸.jpg" style="font-size: 14pt;" width="484"/></span></span></div></div><div style="margin: 0px 0cm; padding: 0px; text-align: justify; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><div><br clear="none"/></div></div><div><span style="font-size: 14pt;"><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-variant-caps: normal; font-variant-ligatures: normal; line-height: 16.2pt;">循环结构：</span><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-variant-caps: normal; font-variant-ligatures: normal; line-height: 16.2pt;">需要重复执行同一操作的程序结构称为循环结构。</span></span></div><div><br clear="none"/></div><div><img src="00-笔记_files/循环.jpg" type="image/jpeg" data-filename="循环.jpg" style="font-size: 14pt;" width="352"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16pt;">if --- 判断逻辑，如果</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 14pt; font-family: 等线;">if(true){</span></div><div><span style="font-size: 14pt; font-family: 等线;">    //会执行的语句</span></div><div><span style="font-size: 14pt; font-family: 等线;">}</span></div><div><br clear="none"/></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">if(false){</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">    //会跳过不执行的语句</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">}</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-family: 等线;">if(判断条件){ //当if括号中结果为true时执行语句1，否则执行语句2</span></span></div><div style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-family: 等线;">    //语句1</span></span></div><div style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-family: 等线;">}else{</span></span></div><div><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-family: 等线;">    //语句2</span></span></div><div><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; font-family: 等线;">}</span></span></div><div><br clear="none"/></div><div><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">if(判断条件1){ //当条件1结果为true时执行语句1</span></div><div style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="box-sizing: border-box; width: 800px; color: rgb(51, 51, 51); font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">    //语句1</span></div><div style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">}else if(<span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">判断条件2</span>){ <span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">//当条件1结果为false而且<span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">条件2结果为true</span>时执行语句2</span></span></div><div><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">    //语句2</span></div><div><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">}else{ <span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">//当条件1<span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">条件2</span>结果都为false</span><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">时执行语句3</span></span></div><div><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">    //语句3</span></div><div><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">}</span></div><div><br clear="none"/></div></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 14pt;"><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">if( 0 ){</span></span></div><div><span style="font-size: 14pt;"><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">    alert(&quot;你猜我会弹么？&quot;);</span></span></div><div><span style="font-size: 14pt;"><span style="box-sizing: border-box; width: 800px; color: #333333; font-variant-ligatures: normal; font-variant-caps: normal; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; font-family: 等线;">}</span></span></div><div><br clear="none"/></div></div><div><br clear="none"/></div><div><span style="font-size: 16px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(51, 51, 51); font-family: &quot;Open Sans&quot;, &quot;Clear Sans&quot;, &quot;Helvetica Neue&quot;, Helvetica, Arial, sans-serif; font-variant-caps: normal; font-variant-ligatures: normal;">我们都知道，if括号中只需要布尔类型值。那么在if判断中，所有的数据类型都会被隐式转换为布尔类型。</span></div><div><br clear="none"/></div><div><span style="font-size: 14pt;"><span style="white-space: pre-wrap; word-wrap: break-word; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="font-size: 14pt; color: rgb(255, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal;">注意：0、-0、</span></span><span style="white-space: pre-wrap; word-wrap: break-word; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; color: rgb(255, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal; line-height: 1.5;">null</span><span style="white-space: pre-wrap; word-wrap: break-word; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; color: rgb(255, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal;">、&quot;&quot;、</span><span style="white-space: pre-wrap; word-wrap: break-word; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; color: rgb(255, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal; line-height: 1.5;">false</span><span style="white-space: pre-wrap; word-wrap: break-word; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt; color: rgb(255, 0, 0); font-variant-caps: normal; font-variant-ligatures: normal;">、undefined 或者 NaN在if条件里结果为false</span></span></div><div><br clear="none"/></div><div><span style="font-size: 14pt;"><span style="letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-size: 14pt;">隐式类型转换</span></span></div><div><br clear="none"/></div><div><span style="font-size: 16px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(51, 51, 51); font-variant-caps: normal; font-variant-ligatures: normal;">    除了+运算符具有两层含义以外，- * /只有数学意义，所以当进行- * /运算的时候默认会将运算符两侧的数据类型隐式转换为数字类型，再进行运算。</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 14pt; font-family: 等线;">var a = 2, b = &quot;2&quot;;</span></div><div><br clear="none"/></div><div><span style="font-size: 14pt; font-family: 等线;">if(a == b){</span></div><div><span style="font-size: 14pt; font-family: 等线;">    alert(&quot;a和b相等&quot;);    // 会弹  </span></div><div><span style="font-size: 14pt; font-family: 等线;">}</span></div><div><br clear="none"/></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">if(a === b){</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">    alert(&quot;a和b相等&quot;);    <span style="font-family: 等线; font-size: 14pt; color: #333333;">// 不会弹  </span></span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">}</span></div><div><br clear="none"/></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">if(1 == true){</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">    alert(&quot;数字1是true&quot;);</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">}</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">if(a = b){</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">    alert(&quot;a和b相等&quot;);</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">}</span></div><div><span style="font-size: 14pt; font-family: 等线; color: #333333;">//一个等号代表赋值操作，结果为等号右边的值</span></div><div><br clear="none"/></div></div><div><br clear="none"/></div><div><span style="font-size: 16pt;">switch  case  多分支语句</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 14pt;">switch(语句){  //语句的结果与每一条case内容进行匹配</span></div><div><span style="font-size: 14pt;">    case 1:</span></div><div><span style="font-size: 14pt;">       alert(1);</span></div><div>           <span style="font-size: 14pt;">break;</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">        case 2:</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">         alert(2);</span></div><div><span style="font-family: Monaco; font-size: 14pt; color: #333333;">             </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">break;</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">case 3:</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">   </span> <span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">alert(3);</span></div><div><span style="font-family: Monaco; font-size: 14pt; color: #333333;">           </span> <span style="font-size: 14pt; font-family: Monaco; color: #333333;">break;</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">        default:</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">            alert(0);</span></div><div><span style="font-size: 14pt;">}</span></div></div><div><br clear="none"/></div><div style="box-sizing: border-box; width: 800px; font-size: 16px; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff;"><span style="box-sizing: border-box; width: 800px; font-size: 16px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(51, 51, 51); font-variant-caps: normal; font-variant-ligatures: normal;">注意switch的应用场景（有多个确定值需要判断的时候）；</span></div><div><span style="box-sizing: border-box; width: 800px; font-size: 16px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(51, 51, 51); font-variant-caps: normal; font-variant-ligatures: normal;">注意case穿透，要加break语句（</span><span style="box-sizing: border-box; width: 800px; font-size: 16px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; font-variant-caps: normal; font-variant-ligatures: normal;"><font style="color: rgb(227, 0, 0);">如果程序没有发现break语句，那么解析器会继续向下解析</font></span><span style="box-sizing: border-box; width: 800px; font-size: 16px; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: pre-wrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(51, 51, 51); font-variant-caps: normal; font-variant-ligatures: normal;">）;</span></div><div><br clear="none"/></div><div style="box-sizing: border-box; padding: 8px; font-family: Monaco, Menlo, Consolas, &quot;Courier New&quot;, monospace; font-size: 12px; color: rgb(51, 51, 51); border-radius: 4px; background-color: rgb(251, 250, 248); border: 1px solid rgba(0, 0, 0, 0.15);-en-codeblock:true;"><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">var a = 1;</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">switch(a){ </span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    case 1:</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">       alert(1);</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    case 2:</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    alert(2);</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">case 3:</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    </span><span style="font-size: 14pt; font-family: Monaco; color: #333333;">   </span> <span style="font-size: 14pt; font-family: Monaco; color: #333333;">alert(3);</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">    default:</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">        alert(0);</span></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">}</span></div><div><br clear="none"/></div><div><span style="font-size: 14pt; font-family: Monaco; color: #333333;">//每一个alert都会被执行，而且alert会阻断程序进程</span></div></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="white-space: pre-wrap;"><span style="font-size: 16pt;">练习</span></span></div><div><span style="font-size: 12pt; color: rgb(1, 1, 1);">    判断一个整数是偶数还是奇数，并输出判断结果</span></div><div><span style="font-size: 12pt; color: rgb(1, 1, 1);">    开发一款软件，根据公式（身高-108）*2=体重，可以有10斤左右的浮动。来观察测试者体重是否合适</span></div><div><span style="font-size: 12pt; color: rgb(1, 1, 1);">   </span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16pt; color: rgb(1, 1, 1); font-family: 微软雅黑; line-height: 150%;">练习</span></div><div><br clear="none"/></div><div><ul><li><div><span style="font-size: 12pt;">点击切换div颜色</span></div></li><li><div><span style="font-size: 12pt;">输入分数，判定成绩等级</span></div></li><li><div><span style="font-size: 12pt;">输入年份，计算某一年是否是闰年</span></div></li><li><div><span style="text-indent: 0pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1);">输入月份，显示当月的天数</span></span></div></li></ul></div><div><span style="font-size: 12pt;">             要求：利用case穿透简化代码</span></div><ul><li><div><span style="font-size: 12pt;">输入数字，显示星期几，如：输入0，弹出星期日，以此类推（两种方法）</span></div></li><li><div><span style="font-size: 12pt;">设计一个猜拳游戏：</span></div><div><span style="font-size: 12pt;">      假设： 1代表石头 2代表剪刀 3代表 布</span></div><div><span style="font-size: 12pt;">      计算机每次随机出现1—3中的任意一个数（parseInt (Math.random()*3) + 1）</span></div><div><span style="font-size: 12pt;">      玩家也有三种状态，用玩家出的数和计算机出的数进行比对，按照游戏规则比出胜负。</span></div><div><br clear="none"/></div></li></ul><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 16pt; color: rgb(1, 1, 1); font-family: 微软雅黑; line-height: 150%;">练习</span></div><div><br clear="none"/></div><div><span style="font-size: 12pt; color: rgb(1, 1, 1);">判断一个三位数是否是水仙花数（如：153 = 1^3 + 5^3 + 3^3，那么153就是水仙花数，水仙花数只有四个：</span> <span style="font-size: 14px; letter-spacing: normal; orphans: 2; text-indent: 28px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif; font-variant-caps: normal; font-variant-ligatures: normal;">153，370，371，407</span><span style="font-size: 12pt; color: rgb(1, 1, 1);">）</span></div><div><span style="text-indent: 0pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1); font-family: ΢���ź�; line-height: 150%;">   </span></span></div><div><span style="text-indent: 0pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1); font-family: ΢���ź�; line-height: 150%;"> 根据一个数字日期，判断这个日期是这一年的第几天</span></span></div><div><span style="font-size: 12pt; text-indent: 0mm; color: rgb(1, 1, 1);">        例如： 20160211，计算后结果为42</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;"><br/></span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div></div><div><br/></div></span>
</div></body></html> 